(defun html-javascript()
  (interactive)
  (insert "<script language=\"javascript\">

</script>")
  )

(defun html-jquery()
  (interactive)
  (insert "<html>
  <head>
  <script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js\"></script>
  </head>

  <body>
  </body>
</html>")
  )

(defun html-html()
  (interactive)
  (insert "<html>
  <title></title>
  <head>
  </head>

  <body>
  </body>
</html> 
")
  )

(defun html-article()
  "html article example"
  (interactive)
  (insert "<!DOCTYPE HTML>
<html>
  <head>
    <title>
      It's going to rain
    </title>
  </head>
  <body>
    <article>
      <header>
        <h1>It's going to rain</h1>
        <p>
          <time pubdate datetime=\"2010-10-09T14:28-08:00\"></time>
        </p>
      </header>
      <p>Current forecast is for bigtime rain.</p>
      <section>
        <h1>Comments</h1>
        <article>
          <footer>
            <p>Posted by: Sam Budd</p>
            <p><time pubdate datetime=\"2010-10-10T19:10-08:00\">
            </time></p>
          </footer>
          <p>We need the rain.</p>
        </article>
        <article>
          <footer>
            <p>Posted by: Fred SMith</p>
            <p><time pubdate datetime=\"2010-10-10T19:15-08:00\">
            </time></p>
          </footer>
          <p>Maybe you do. I don't.</p>
        </article>
      </section>
    </article>
  </body>
</html>")
  )

(defun html-h1()
  (interactive)
  (insert "<h1></h1>")
  )

(defun html-button()
  (interactive)
  (insert "<button type=\"button\" onclick=\"displayDate()\">Display Date</button>")
  )

(defun javascript-function(&optional functionName)
  (interactive)
  (or functionName (setq functionName (read-from-minibuffer "Enter Function Name: ")))
  (insert (format "function %s(){

}" functionName))
  )

(defun html-table()
  (interactive)
  (insert "<table border=\"1\">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>")
  )

(defun html-form()
  (interactive)
  (insert "<form name=\"input\" action=\"html_form_action.asp\" method=\"get\">
Username: <input type=\"text\" name=\"user\">
<input type=\"submit\" value=\"Submit\">
</form>")
  )

(defun html-div()
  (interactive)
  (insert "<!DOCTYPE html>
<html>
<body>

<div id=\"container\" style=\"width:500px\">

<div id=\"header\" style=\"background-color:#FFA500;\">
<h1 style=\"margin-bottom:0;\">Main Title of Web Page</h1></div>

<div id=\"menu\" style=\"background-color:#FFD700;height:200px;width:100px;float:left;\">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript</div>

<div id=\"content\" style=\"background-color:#EEEEEE;height:200px;width:400px;float:left;\">
Content goes here</div>

<div id=\"footer\" style=\"background-color:#FFA500;clear:both;text-align:center;\">
</div>

</div>

</body>
</html> ")
  )

(defun html-a()
  (interactive)
  (insert "<a href=\"default.asp\">HTML Tutorial</a>")
  )

(defun html-image()
  (interactive)
  (insert "<img src=\"w3schools.jpg\" width=\"104\" height=\"142\"> ")
  )

(defun html-canvas()
  (interactive)
  (insert "<script>
/*
var c=document.getElementById(\"myCanvas\");
var ctx=c.getContext(\"2d\");
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();
*/

/*
var c=document.getElementById(\"myCanvas\");
var ctx=c.getContext(\"2d\");
ctx.font=\"30px Arial\";
ctx.fillText(\"Hello Canvas\",10,50);
*/

/*
var c=document.getElementById(\"myCanvas\");
var ctx=c.getContext(\"2d\");

// Create gradient
var grd=ctx.createLinearGradient(0,0,200,0);
grd.addColorStop(0,\"red\");
grd.addColorStop(1,\"white\");

// Fill with gradient
ctx.fillStyle=grd;
ctx.fillRect(10,10,150,80);
*/

</script>

<canvas id=\"myCanvas\" width=\"200\" height=\"100\"
style=\"border:1px solid #000000;\">
</canvas> ")
  )

(defun html-json-eval()
  (interactive)
  (insert "<html>
  <title></title>
  <head>
  </head>

  <body>
    First Name: <span id=\"fname\"></span><br />
    Last Name: <span id=\"lname\"></span><br />


    <script language=\"javascript\">

      var txt = '{ \"employees\" : [' +
      '{ \"firstName\":\"John\" , \"lastName\":\"Doe\" },' +
      '{ \"firstName\":\"Anna\" , \"lastName\":\"Smith\" },' +
      '{ \"firstName\":\"Peter\" , \"lastName\":\"Jones\" } ]}';

      var obj = eval (\"(\" + txt + \")\");
      
      document.getElementById(\"fname\").innerHTML = obj.employees[1].firstName
      document.getElementById(\"lname\").innerHTML = obj.employees[1].lastName 
    </script>

  </body>
</html> 
")
  )

(defun html-jason()
  (interactive)
  (insert "<!DOCTYPE html>
<html>
<body>
<h2>JSON Object Creation in JavaScript</h2>

<p>
Name: <span id=\"jname\"></span><br />
Age: <span id=\"jage\"></span><br />
Address: <span id=\"jstreet\"></span><br />
Phone: <span id=\"jphone\"></span><br />
</p>

<script>
var JSONObject= {
\"name\":\"John Johnson\",
\"street\":\"Oslo West 555\",
\"age\":33,
\"phone\":\"555 1234567\"};
document.getElementById(\"jname\").innerHTML=JSONObject.name
document.getElementById(\"jage\").innerHTML=JSONObject.age
document.getElementById(\"jstreet\").innerHTML=JSONObject.street
document.getElementById(\"jphone\").innerHTML=JSONObject.phone
</script>

</body>
</html>")
  )

(defun html-ajax()
  (interactive)
  (insert "<!DOCTYPE html>
<html>
<head>
<script>
function showCustomer(str)
{
var xmlhttp;    
if (str==\"\")
  {
  document.getElementById(\"txtHint\").innerHTML=\"\";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(\"txtHint\").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open(\"GET\",\"getcustomer.asp?q=\"+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form action=\"\"> 
<select name=\"customers\" onchange=\"showCustomer(this.value)\">
<option value=\"\">Select a customer:</option>
<option value=\"ALFKI\">Alfreds Futterkiste</option>
<option value=\"NORTS \">North/South</option>
<option value=\"WOLZA\">Wolski Zajazd</option>
</select>
</form>
<br>
<div id=\"txtHint\">Customer info will be listed here...</div>

</body>
</html>")
  )
(defun html-css()
  (interactive)
  (insert "<style>
body
{
  color:orange;
}
</style>
")
  )

(defun html-css-value()
  (interactive)
  (insert "background-color:#d0e4fe;
background-color
background-image
background-repeat
background-attachment
background-position
color:orange;
font-family:\"Times New Roman\";
font-size:20px;
margin-left:1em;
margin-bottom:0.5em;
text-align:center;
text-decoration:none;
line-height:40px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
")
  )

(defun html-fieldset()
  (interactive)
  (insert "<fieldset>
    <legend>Login</legend>

    </fieldset>")
  )

(defun javascript-debug()
  (interactive)
  (insert "function print_call_stack() {
  var stack = new Error().stack;
  console.log(\"PRINTING CALL STACK\");
  console.log( stack );
}")
  )

(defun jquery-progressbar()
  "jquery progress bar"
  (interactive)
  (insert "<!doctype html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<title>jQuery UI Progressbar - Default functionality</title>
<link rel=\"stylesheet\" href=\"//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css\">
<script src=\"//code.jquery.com/jquery-1.9.1.js\"></script>
<script src=\"//code.jquery.com/ui/1.10.4/jquery-ui.js\"></script>
<link rel=\"stylesheet\" href=\"/resources/demos/style.css\">
<script>
$(function() {
$( \"#progressbar\" ).progressbar({
value: 37
});
});
</script>
</head>
<body>
<div id=\"progressbar\"></div>
</body>
</html>")
  )

(defun jquery-autocomplete()
  "jquery auto complete"
  (interactive)
  (insert " <!doctype html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel=\"stylesheet\" href=\"//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css\">
<script src=\"//code.jquery.com/jquery-1.9.1.js\"></script>
<script src=\"//code.jquery.com/ui/1.10.4/jquery-ui.js\"></script>
<link rel=\"stylesheet\" href=\"/resources/demos/style.css\">
<script>
$(function() {
var availableTags = [
\"ActionScript\",
\"AppleScript\",
\"Asp\",
\"BASIC\",
\"C\",
\"C++\",
\"Clojure\",
\"COBOL\",
\"ColdFusion\",
\"Erlang\",
\"Fortran\",
\"Groovy\",
\"Haskell\",
\"Java\",
\"JavaScript\",
\"Lisp\",
\"Perl\",
\"PHP\",
\"Python\",
\"Ruby\",
\"Scala\",
\"Scheme\"
];
$( \"#tags\" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class=\"ui-widget\">
<label for=\"tags\">Tags: </label>
<input id=\"tags\">
</div>
</body>
</html>")
  )

(defun jquery-colorAnimation()
  "jquery color animation"
  (interactive)
  (insert "<!doctype html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<title>jQuery UI Effects - Animate demo</title>
<link rel=\"stylesheet\" href=\"//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css\">
<script src=\"//code.jquery.com/jquery-1.9.1.js\"></script>
<script src=\"//code.jquery.com/ui/1.10.4/jquery-ui.js\"></script>
<link rel=\"stylesheet\" href=\"/resources/demos/style.css\">
<style>
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { width: 240px; height: 135px; padding: 0.4em; position: relative; background: #fff; }
#effect h3 { margin: 0; padding: 0.4em; text-align: center; }
</style>
<script>
$(function() {
var state = true;
$( \"#button\" ).click(function() {
if ( state ) {
$( \"#effect\" ).animate({
backgroundColor: \"#aa0000\",
color: \"#fff\",
width: 500
}, 1000 );
} else {
$( \"#effect\" ).animate({
backgroundColor: \"#fff\",
color: \"#000\",
width: 240
}, 1000 );
}
state = !state;
});
});
</script>
</head>
<body>
<div class=\"toggler\">
<div id=\"effect\" class=\"ui-widget-content ui-corner-all\">
<h3 class=\"ui-widget-header ui-corner-all\">Animate</h3>
<p>
Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
</p>
</div>
</div>
<a href=\"#\" id=\"button\" class=\"ui-state-default ui-corner-all\">Toggle Effect</a>
</body>
</html>")
  )

(defun javascript-basic()
  ""
  (interactive)
  (insert "function inchestometers(inches)
   {
   if (inches < 0)
      return -1;
   else
      {
      var meters = inches / 39.37;
      return meters;
      }
   }

var inches = 12;
var meters = inchestometers(inches);
document.write(\"the value in meters is \" + meters);
")
  )


(defun javascript-recursion()
  ""
  (interactive)
  (insert "function factorial(num)
{
    // If the number is less than 0, reject it.
    if (num < 0) {
        return -1;
    }
    // If the number is 0, its factorial is 1.
    else if (num == 0) {
        return 1;
    }
    var tmp = num;
    while (num-- > 2) {
        tmp *= num;
    }
    return tmp;
}

var result = factorial(8);
document.write(result);
")
  )


(defun javascript-displayText()
  ""
  (interactive)
  (insert "<div id=\"textDiv\"></div>
<script type=\"text/javascript\">
    var div = document.getElementById(\"textDiv\");
    div.textContent = \"my text\";
    var text = div.textContent;
</script>


<!DOCTYPE html>
<html>
<head>
<script type=\"text/javascript\">
    function ShowTime()
    {
        var dt = new Date();
        document.write(dt.toTimeString());
        // var elem = document.getElementById(\"divElem\");
        // elem.textContent = dt.toTimeString();
        window.setTimeout(\"ShowTime();\", 5000);
    }
</script>
</head>

<body>
<script type=\"text/javascript\">
    ShowTime();
</script>
<div id=\"myDiv\"></div>
</body>
</html>
")
  )


(defun javascript-print()
  ""
  (interactive)
  (insert "var myName = arguments.callee.toString();
   myName = myName.substr('function '.length);
   myName = myName.substr(0, myName.indexOf('('));

   alert(myName);")
  )

(defun javascript-print-howToUse()
  ""
  (interactive)
  (insert "var sum = function(a, b) { var myName = arguments.callee.toString();
      alert(myName);
      return a + b; }

      alert(sum(5, 5));")
  )

(defun javascript-write-to-file()
  ""
  (interactive)
  (insert "var f = \"C:\\\\temp\\\\sometextfile.txt\";

writeTextFile(f, \"Spoon\")
writeTextFile(f, \"Cheese monkey\")
writeTextFile(f, \"Onion\")


function writeTextFile(afilename, output)
{
  var txtFile = new File(afilename);
  // txtFile.open(\"w\"); // destroys contents and works fine
  // txtFile.open(\"e\"); // seems to mess contents around
  txtFile.writeln(output);
  txtFile.close();
}")
  )


(defun vbscript-fileIO()
  ""
  (interactive)
  (insert "Dim fso, MyFile
Set fso = CreateObject(\"Scripting.FileSystemObject\")
Set MyFile = fso.CreateTextFile(\"output.txt\",True)

MyFile.WriteLine(\"\")")
  )
